import 'package:ft_reader/common/utils/constans.dart';

final String tableBook = 'book';
final String columnId = 'Id';
final String columnName = 'Name';
final String columnAuthor = 'Author';
final String columnImg = 'Img';
final String columnDesc = 'Desc';
final String columnBookStatus = 'BookStatus';
final String columnLastChapterId = 'LastChapterId';
final String columnLastChapter = 'LastChapter';
final String columnCName = 'CName';
final String columnUpdateTime = 'UpdateTime';
final String columnPosition = 'Positon';

class BookBean {
  int id;
  int position;
  String name;
  String author;
  String img;
  String desc;
  String bookStatus;
  String lastChapterId;
  String lastChapter;
  String cname;
  String updateTime;

  static BookBean fromMap(Map<String, dynamic> map) {
    if (map == null) {
      return null;
    }
    BookBean book = BookBean();
    book.id = int.parse(map['Id'].toString());
    book.position = map['Positon'] ?? 0;
    book.name = map['Name'] ?? "";
    book.author = map['Author'] ?? "";
    book.img = getCompleteImgUrl(map['Img'].toString()) ?? "";
    book.desc = map['Desc'] ?? "";
    book.bookStatus = map['BookStatus'] ?? "";
    book.lastChapterId = map['LastChapterId'] ?? "";
    book.lastChapter = map['LastChapter'] ?? "";
    book.cname = map['CName'] ?? "";
    book.updateTime = map['UpdateTime'] ?? "";
    return book;
  }

  static BookBean fromListDetailMap(Map<String, dynamic> map) {
    if (map == null) return null;
    BookBean book = BookBean();
    book.id = int.parse(map['BookId'].toString());
    book.position = map['Positon'] ?? 0;
    book.name = map['BookName'] ?? "";
    book.author = map['Author'] ?? "";
    book.img = getCompleteImgUrl(map['BookImage'].toString()) ?? "";
    book.desc = map['Description'] ?? "";
    book.bookStatus = "";
    book.lastChapterId = "";
    book.lastChapter = "";
    book.cname = map['CategoryName'] ?? "";
    book.updateTime = "";
    return book;
  }
  Map<String, dynamic> toMap() {
    var map = <String, dynamic>{
      columnName: name,
      columnAuthor: author,
      columnImg: img,
      columnDesc: desc,
      columnBookStatus: bookStatus,
      columnLastChapterId: lastChapterId,
      columnLastChapter: lastChapter,
      columnCName: cname,
      columnUpdateTime: updateTime,
      columnPosition: position,
    };
    if (id != null) {
      map[columnId] = id;
    }
    return map;
  }
}
